package com.sum.tea.viewmodel

import androidx.lifecycle.ViewModel
import com.blankj.utilcode.util.ConvertUtils
import com.blankj.utilcode.util.ToastUtils
import com.sum.common.bean.ReaderExt.READER_ERR
import com.sum.common.manager.UHFManager
import com.sum.common.utils.ByteUtil

class DestructionViewModel : ViewModel() {
    fun killTag(password: String) {
        val passWord = if(UHFManager.getInstance().isXinlianDevice){
            val rpaswd = ByteArray(4)
            if(password.isNotEmpty()){
                ByteUtil.Str2Hex(password, password.length,rpaswd)
            }
            rpaswd
        }else {
            ConvertUtils.hexString2Bytes(password)
        }
        val result = UHFManager.getInstance().currentManager.killTag(passWord, 1000)
        if (result == READER_ERR.MT_OK_ERR) {
            ToastUtils.showShort("kill success")
        } else {
            ToastUtils.showShort("kill fail")
        }
    }
}
